package com.example.util;

import com.example.model.TBit;
import com.example.service.TBitServiceImpl;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: yuanjianpeng
 * @Date: 2019/4/21 16:00
 * @Description:
 */
public class LikeSearchInit implements InitializingBean, ApplicationContextAware {

    @Autowired
    TBitServiceImpl tBitService;

    ApplicationContext applicationContext;

    public static Map<String, String> likeSearch = new HashMap<>(); //应该使用LikeSearc的对象，这里用map代替

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("start to overload data");
        List<TBit> bitList = tBitService.searchAll();
        for (TBit tBit : bitList) {
            likeSearch.put(tBit.getK(), tBit.getV());
        }
        System.out.println("overload data end");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
